package cn.edu.ujn.lab3.service.impl;


import cn.edu.ujn.lab3.dao.Invoice;
import cn.edu.ujn.lab3.dao.InvoiceMapper;
import cn.edu.ujn.lab3.service.InvoiceService;
import cn.edu.ujn.lab3.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("invoiceService")
@Transactional
public class InvoiceServiceImpl implements InvoiceService {

    @Autowired
    private InvoiceMapper invoiceDao;
    
    //查询发票列表
    @Override
    public Page<Invoice> findInvoiceList(Integer page, Invoice invoice) {
        invoice.setStart((page - 1) * invoice.getRows());
        List<Invoice> invoiceList = invoiceDao.selectInvoiceList(invoice);
        Integer count = invoiceDao.selectInvoiceListCount(invoice);
        Page<Invoice> invoicePage = new Page<Invoice>();
        invoicePage.setPage(page);
        invoicePage.setRows(invoiceList);
        invoicePage.setTotal(count);
        invoicePage.setSize(invoice.getRows());
        return invoicePage;
    }

	//创建发票
    @Override
	public int createInvoice(Invoice invoice) {
		// TODO Auto-generated method stub
		 return invoiceDao.insertSelective(invoice);
	}
    //通过id查询发票
	@Override
	public Invoice getInvoiceById(Integer id) {
		// TODO Auto-generated method stub
		return invoiceDao.selectByPrimaryKey(id);
	}
	//更新发票
	@Override
	public int updateInvoice(Invoice invoice) {
		// TODO Auto-generated method stub
		return invoiceDao.updateByPrimaryKeySelective(invoice);
	}
	//删除发票
	@Override
    public int deleteInvoice(Integer id) {
        return invoiceDao.deleteByPrimaryKey(id);
    }
	
	
}
